package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.UserFollowDao;
import com.atguigu.entity.UserFollow;
import com.atguigu.service.DictService;
import com.atguigu.service.UserFollowService;
import com.atguigu.service.UserInfoService;
import com.atguigu.vo.UserFollowVo;
import com.base.BaseDao;
import com.base.BaseServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = UserFollowService.class)
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {

    @Autowired
    private UserFollowDao userFollowDao;
    @Reference
    private DictService dictService;
    @Override
    protected BaseDao<UserFollow> getEntityDao() {
        return userFollowDao;
    }

    @Override
    public boolean isFollow(Long houseId, Long UserInfoId) {
        int rows = userFollowDao.isFollow(houseId,UserInfoId);
        if(rows > 0){
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<UserFollowVo> findListPage(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum,pageSize);
        Page<UserFollowVo> page = userFollowDao.findListPage(userId);
        List<UserFollowVo> userFollowVoList = page.getResult();
        for(UserFollowVo userFollowVo:userFollowVoList){
            String houseTypeName = this.dictService.getNameById(userFollowVo.getHouseTypeId());
            userFollowVo.setHouseTypeName(houseTypeName);
            String floorName = this.dictService.getNameById(userFollowVo.getFloorId());
            userFollowVo.setFloorName(floorName);
            String directionName = this.dictService.getNameById(userFollowVo.getDirectionId());
            userFollowVo.setDirectionName(directionName);
        }
        return new PageInfo<>(userFollowVoList);
    }

    @Override
    public void cancelFollow(Long id) {
        userFollowDao.cancelFollow(id);
    }
}
